Per bug 28901, and Duplicatebug on r105831, only list the Article ID if it has alread...
authorSam Reed <reedy@users.mediawiki.org>
Sat, 17 Dec 2011 19:55:49 +0000 (19:55 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Sat, 17 Dec 2011 19:55:49 +0000 (19:55 +0000)
Not a long term fix, but saves potentially a lot of database queries to lookup article ids, until the other issues on bug 28901 are tidied up

includes/Title.php
includes/api/ApiQueryBase.php

index aa96b95..6dd79d2 100644 (file)
@@ -2807,6 +2807,15 @@ class Title {
                return $this->mCounter;
        }
 
+       /**
+        * Returns a bool to say whether the Article ID for this title has already been loaded
+        *
+        * @return bool
+        */
+       public function isArticleIDLoaded() {
+               return $this->mArticleID != -1;
+       }
+
        /**
         * Get the article ID for this Title from the link cache,
         * adding it if necessary
@@ -2825,10 +2834,8 @@ class Title {
                        $linkCache->clearLink( $this );
                        $this->mArticleID = $linkCache->addLinkObj( $this );
                        $linkCache->forUpdate( $oldUpdate );
-               } else {
-                       if ( -1 == $this->mArticleID ) {
-                               $this->mArticleID = $linkCache->addLinkObj( $this );
-                       }
+               } else if ( -1 == $this->mArticleID ) {
+                       $this->mArticleID = $linkCache->addLinkObj( $this );
                }
                return $this->mArticleID;
        }
index e3cf51f..fdaa630 100644 (file)
@@ -304,7 +304,11 @@ abstract class ApiQueryBase extends ApiBase {
         */
        public static function addTitleInfo( &$arr, $title, $prefix = '' ) {
                $arr[$prefix . 'ns'] = intval( $title->getNamespace() );
-               $arr[$prefix . 'pageid'] = $title->getArticleID();
+               // TODO: This is a workaround for bug 28901, as the Article ID isn't always loaded
+               // Saves many DB queries, but does need cleaning up, so callers have always loaded the Article ID also
+               if ( $title->isArticleIDLoaded() ) {
+                       $arr[$prefix . 'pageid'] = $title->getArticleID();
+               }
                $arr[$prefix . 'title'] = $title->getPrefixedText();
        }